﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;

namespace SCIMC
{
    /// <summary>
    /// Summary description for AutoCompleteProcessador
    /// </summary>
    public class AutoCompleteProcessador : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string descricao = context.Request.QueryString["q"];
            string sql = "SELECT Descricao FROM tbAutoCompleteProcessador where Descricao like '%" + descricao + "%' and Ativo = 1;";
            string conexao = System.Configuration.ConfigurationManager.AppSettings["StringConexao"];
            using (SqlConnection connection = new SqlConnection(conexao))
            using (SqlCommand command = new SqlCommand(sql, connection))
            {
                connection.Open();

                using (SqlDataReader reader = command.ExecuteReader())
                {
                    List<string> list = new List<string>();
                    while (reader.Read())
                    {
                        context.Response.Write(reader[0].ToString() + Environment.NewLine);
                    }
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}